﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sol_NetCoreDemo.JWT;

namespace Sol_NetCoreDemo.Controllers.JWT
{
    [Route("api/[controller]")]
    [ApiController]
    public class JWTGetController : ControllerBase
    {
        [HttpGet("Test")]
        public ActionResult Test(string userName)
        {
            var token = TokenJWT.GenerateToken(userName);
            return Ok(token);
        }

        [HttpPost("Test2")]
        public ActionResult Test2([FromBody]User user)
        {
            string passWord = Request.Query["passWord"];
            var token = TokenJWT.GenerateToken(user.userName);
            return Ok(token);
        }



        [HttpGet("TestCheck")]
        public ActionResult TestCheck()
        {
            string account = string.Empty;
            try
            {
                account = HttpContext.User.Claims.First(c => c.Type == "Account").Value;
            }
            catch (Exception ex)
            {
                account = ex.ToString();
                account = "验证失败";
            }
            return Ok(account);
        }

    }

    public class User
    {
        public string userName { get; set; }
    }
}